package com.softserveinc.fragments.map;

import java.util.ArrayList;
import java.util.List;

import android.graphics.drawable.Drawable;

import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class MovieItemizedOverlay extends BalloonItemizedOverlay {

	private final List<OverlayItem> overlays = new ArrayList<OverlayItem>();
	private final List<OnItemTapListener> itemTapListeners = new ArrayList<MovieItemizedOverlay.OnItemTapListener>();

	public MovieItemizedOverlay(final MapPopup mapPopup, final MapView mapView,
			final Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker), mapPopup, mapView);
	}

	public void addOverlay(final OverlayItem overlay,
			final OnItemTapListener listener) {
		overlays.add(overlay);
		itemTapListeners.add(listener);
		populate();
	}

	@Override
	protected OverlayItem createItem(final int i) {
		return overlays.get(i);
	}

	@Override
	public int size() {
		return overlays.size();
	}

	@Override
	protected boolean onBalloonTap(final int index, final OverlayItem item) {
		OnItemTapListener itemTapListener = itemTapListeners.get(index);

		if (itemTapListener != null) {
			itemTapListener.onItemTap();
		}

		return true;
	}

	public interface OnItemTapListener {
		void onItemTap();
	}
}
